	
	$(function(){
		
		/**
		*	页面加载完成后执行
		*/
		$(document).ready(function(){
			$(".daoda").each(function(){
				var status=$(this).attr("status");
				if(status!=0){
					$(this).attr("disabled",true);//设置为不可点击
					$(this).attr("src","../image/daoda_unclick.png")//改变背景图片
				}
			})
		});
		
		
		
		/**
		*	点击到达按钮
		*/
		$(".daoda").click(function(){
			var myDate = new Date();    
			var year=myDate.getFullYear();
			var month=myDate.getMonth() + 1;
			if(month<10){
				month="0"+month;
			}
			var day=myDate.getDate();
			if(day<10){
				day="0"+day;
			}
			var date=year+"-"+month+"-"+day;
			var riqi=$(this).parent().siblings(".date").text().trim();
			if(date!=riqi){
				 top.layer.msg('对不起！只能设置当天预约！',{icon: 2, time: 1000});
			}else{
				var id=$(this).parent().siblings(".td1").find(".apt_id").val();
				//console.log(id);
				var renshu=$(this).parent().prev().prev().html();
				layer.confirm('确定用户到达吗？到达会自动安排餐桌',{
						btn:["确定","取消"]
					},function(){
						//是否是数字
					if( /^\d|(\d*\.\d+)*/.test(renshu)) {
							if(1<=renshu||12>=renshu){
							$.ajax({
							type:"post",
							data:{aptId:id,renshu:renshu},
							url:"../appoint/updateStatsArrangeTable",
							dataType:"json",
							success:function(data){
					        	//var index = layer.load(0, {shade: false});
					        	//console.log(data.result);控制台输出
								if(data.message!=null){
					        		layer.msg(data.message, {
		 								icon : 2,
		 								time : 3000
		 							},function(){
		 								location.reload();
		 							});
					        		return false;
					        	}
								if(data.result!=null){
		 			        	layer.msg(data.result, {
		 								icon : 1,
		 								time : 2000
		 							},function(){
 		 								$(this).attr("disabled",true);//设置为不可点击
		 								$(this).attr("src","../image/daoda_unclick.png")//改变背景图片
		 								location.reload();
		 							});
								}
							},
							error:function(data){
					        	if(data.message!=null){
					        		layer.msg(data.message, {
		 								icon : 2,
		 								time : 3000
		 							},function(){
		 								location.reload();
		 							});
					        		return false;
					        	}
					        }
								}); 
							}else{
				layer.alert('没有那么大的桌子!', { skin: 'demo-class', icon: 2, time: 1500, title:'提示', closeBtn: 0});
							}
							}else{
				layer.alert('人数只能是数字!', { skin: 'demo-class', icon: 2, time: 1500, title:'提示', closeBtn: 0});
							}
					});
					
			}		
			
		});
		
		
		
		/**
		*	点击搜索按钮
		*/
		$(".search").click(function(){
			var number=$("#number").val();
			var phone=$("#phone").val();
			var date=$("#hello3").val();
			console.log(number);
			console.log(phone);
			console.log(date);
			if(number.length==0&&phone.length==0&&date.length==0){
				 top.layer.msg('请输入条件',{icon: 3, time: 1000});
				 return false;
			}
			/*isPhone(phone);
			function isPhone(phone){
			    var result=phone.match(/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/);
			    if(result==null){
			    	 top.layer.msg('请输入正确电话号码!',{icon: 2, time: 1000, area: ['100px', '90px'], });
			    	 return false;
			    }else{*/
			    	if(number==''||phone==''){
						 top.layer.msg('请填写相关条件',{icon: 3, time:1000});
						 return false;
					}else{
						location.href="../appoint/appointmentshow?number="+number+"&phone="+phone+'&startTime'+date;
					}
			/*    }
			}  */
		
			
			
		});
		
		/**
		*	查看所有预约记录
		*/
		$(".check_all").click(function(){
			
			location.href="../appoint/appointmentshow?pageNow=1&pageSize=10";
		});
		
	});
	